package net.soevar.database.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(schema = "public", name = "berita")
public class Berita implements Serializable {
	private static final long serialVersionUID = -3394076168302850312L;
	private long id;
	private String judul;
	private JenisBerita jenisBerita;
	private String isi;
	private Status status;
	private Date tanggalUpload = new Date();
	private String dirubahOleh;
	private Date dirubahTanggal = new Date();

	@Id
	@Column(name = "id", unique = true, nullable = false, length = 255)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(name = "judul", nullable = false)
	public String getJudul() {
		return judul;
	}

	public void setJudul(String judul) {
		this.judul = judul;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "jenis_berita", nullable = true)
	public JenisBerita getJenisBerita() {
		return jenisBerita;
	}

	public void setJenisBerita(JenisBerita jenisBerita) {
		this.jenisBerita = jenisBerita;
	}

	@Column(name = "isi", length = 10000)
	public String getIsi() {
		return isi;
	}

	public void setIsi(String isi) {
		this.isi = isi;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "status", nullable = true)
	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Column(name = "tanggal_upload")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getTanggalUpload() {
		return tanggalUpload;
	}

	public void setTanggalUpload(Date tanggalUpload) {
		this.tanggalUpload = tanggalUpload;
	}

	@Column(name = "dirubah_oleh", length = 100)
	public String getDirubahOleh() {
		return dirubahOleh;
	}

	public void setDirubahOleh(String dirubahOleh) {
		this.dirubahOleh = dirubahOleh;
	}

	@Column(name = "dirubah_tanggal")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDirubahTanggal() {
		return dirubahTanggal;
	}

	public void setDirubahTanggal(Date dirubahTanggal) {
		this.dirubahTanggal = dirubahTanggal;
	}

}
